package com.example.testing;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.view.View.OnClickListener;
import android.widget.ArrayAdapter;
import android.widget.EditText;
import android.widget.Spinner;

public class AddUser extends Activity implements OnClickListener {
	String URL = "http://smoothalicious.nl/webservice/user/login.php",
    		result = "result",
    		details = "details",
    		entryTest = "entryTest",
    		firstname, lastname, email, password, className;
	
    ArrayAdapter<CharSequence> arrayAdapter;
    UserManagement userManagement;
    Intent intent;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		
		this.requestWindowFeature(Window.FEATURE_NO_TITLE);
      	this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
      	
      	setContentView(R.layout.add_user);

  		arrayAdapter = ArrayAdapter.createFromResource(this, R.array.classes, android.R.layout.simple_spinner_item);
  		arrayAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
  		((Spinner)findViewById(R.id.className)).setAdapter(arrayAdapter);
  		
		findViewById(R.id.register).setOnClickListener(this);
	}

	public void onClick(View view) {
		firstname = ((EditText)findViewById(R.id.firstname)).getText().toString();
		lastname = ((EditText)findViewById(R.id.lastname)).getText().toString();
		email = ((EditText)findViewById(R.id.email)).getText().toString();
		password = ((EditText)findViewById(R.id.password)).getText().toString();
		className = ((Spinner)findViewById(R.id.className)).getSelectedItem().toString();
		
		userManagement = new UserManagement(this);
		userManagement.addUser(firstname, lastname, email, password, className);
	}
	
	@Override
	public void onBackPressed() {
		intent = new Intent(AddUser.this, AddUser.class);
        intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        AddUser.this.startActivity(intent);
	}
}

